"use strict";
const fs = require("fs");
const path = require("path");
const DEFAULT_REPLACES = {
  "element-ui/packages/theme-chalk/src/tag.scss": {
    "mix($--tag-primary-color, $--color-white, $backgroundColorWeight)": "var(--color-primary-#{$backgroundColorWeight})",
    "mix($--tag-primary-color, $--color-white, $borderColorWeight)": "var(--color-primary-#{$borderColorWeight})",
    "mix($--tag-primary-color, $--color-white, $fontColorWeight)": "var(--color-primary-#{$fontColorWeight})",
    "color: $--color-white;": "color: var(--color-text-dark-primary);",
    "mix($--tag-primary-color, $--color-white, $hoverColorWeight)": "var(--color-primary-#{$hoverColorWeight})",
    "mix($--tag-info-color, $--color-white, $backgroundColorWeight)": "var(--color-info-#{$backgroundColorWeight})",
    "mix($--tag-info-color, $--color-white, $borderColorWeight)": "var(--color-info-#{$borderColorWeight})",
    "mix($--tag-info-color, $--color-white, $fontColorWeight)": "var(--color-info-#{$fontColorWeight})",
    "mix($--tag-info-color, $--color-white, $hoverColorWeight)": "var(--color-info-#{$hoverColorWeight})",
    "mix($--tag-success-color, $--color-white, $backgroundColorWeight)": "var(--color-success-#{$backgroundColorWeight})",
    "mix($--tag-success-color, $--color-white, $borderColorWeight)": "var(--color-success-#{$borderColorWeight})",
    "mix($--tag-success-color, $--color-white, $fontColorWeight)": "var(--color-success-#{$fontColorWeight})",
    "mix($--tag-success-color, $--color-white, $hoverColorWeight)": "var(--color-success-#{$hoverColorWeight})",
    "mix($--tag-warning-color, $--color-white, $backgroundColorWeight)": "var(--color-warning-#{$backgroundColorWeight})",
    "mix($--tag-warning-color, $--color-white, $borderColorWeight)": "var(--color-warning-#{$borderColorWeight})",
    "mix($--tag-warning-color, $--color-white, $fontColorWeight)": "var(--color-warning-#{$fontColorWeight})",
    "mix($--tag-warning-color, $--color-white, $hoverColorWeight)": "var(--color-warning-#{$hoverColorWeight})",
    "mix($--tag-danger-color, $--color-white, $backgroundColorWeight)": "var(--color-danger-#{$backgroundColorWeight})",
    "mix($--tag-danger-color, $--color-white, $borderColorWeight)": "var(--color-danger-#{$borderColorWeight})",
    "mix($--tag-danger-color, $--color-white, $fontColorWeight)": "var(--color-danger-#{$fontColorWeight})",
    "mix($--tag-danger-color, $--color-white, $hoverColorWeight)": "var(--color-danger-#{$hoverColorWeight})",
    "genTheme(10%, 20%, 100%, 100%)": "genTheme(1, 3, 6, 6)",
    "@include genTheme(100%, 100%, 0, 80%);": `@include genTheme(6, 6, 6, 4);
      color: var(--color-text-dark-primary);
      &.el-tag--info,
      &.el-tag--success,
      &.el-tag--warning,
      &.el-tag--danger {
        color: var(--color-text-dark-primary);
      }
      .el-tag__close {
        color: var(--color-text-dark-primary);
        &:hover {
          color: var(--color-text-dark-primary);
        }
      }
    `,
    "@include genTheme(0, 40%, 100%, 100%);": `@include genTheme(1, 6, 6, 6);
      background: none;
      &.el-tag--info,
      &.el-tag--success,
      &.el-tag--warning,
      &.el-tag--danger {
        background: none;
      }
    `
  },
  "element-ui/packages/theme-chalk/src/pagination.scss": {
    "color: $--color-white;": "color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/autocomplete.scss": {
    "color: #999;": "color: $--color-text-secondary;"
  },
  "element-ui/packages/theme-chalk/src/dropdown.scss": {
    "mix(white, transparent, 50%)": "var(--color-white-5)",
    "mix($--button-default-border-color, transparent, 50%)": "var(--button-default-border-color-5)",
    "background-color: $--color-white;": "background-color: $--popover-background-color;"
  },
  "element-ui/packages/theme-chalk/src/menu.scss": {
    "border-right: solid 1px #e6e6e6;": "border-right: 1px solid $--border-color-lighter;",
    "border-bottom: solid 1px #e6e6e6;": "border-bottom: solid 1px $--border-color-lighter;"
  },
  "element-ui/packages/theme-chalk/src/mixins/_button.scss": {
    "@mixin button-plain($color) {": "@mixin button-plain($colorWeight) { $color: var(--color-#{$colorWeight}); ",
    "mix($--color-white, $color, 90%)": "var(--color-#{$colorWeight}-1)",
    "mix($--color-white, $color, 60%)": "var(--color-#{$colorWeight}-3)",
    "background: $color;": "background: var(--color-#{$colorWeight});",
    "border-color: $color;": "border-color: var(--color-#{$colorWeight});",
    "color: $--color-white;": "color: var(--color-text-dark-primary);",
    "mix($--color-black, $color, $--button-active-shade-percent)": "var(--color-#{$colorWeight}-7)",
    "mix($--color-white, $color, 40%)": "var(--color-#{$colorWeight}-3)",
    "mix($--color-white, $color, 80%)": "var(--color-#{$colorWeight}-3)",
    "@mixin button-variant($color, $background-color, $border-color)": "@mixin button-variant($color, $background-color)",
    "background-color: $background-color;": "background-color: var(--color-#{$background-color});",
    "border-color: $border-color;": "border-color: var(--color-#{$background-color});",
    "mix($--color-white, $background-color, $--button-hover-tint-percent)": "var(--color-#{$background-color}-5)",
    "mix($--color-white, $border-color, $--button-hover-tint-percent)": "var(--color-#{$background-color}-5)",
    "mix($--color-black, $background-color, $--button-active-shade-percent)": "var(--color-#{$background-color}-7)",
    "mix($--color-black, $border-color, $--button-active-shade-percent)": "var(--color-#{$background-color}-7)",
    "mix($background-color, $--color-white)": "var(--color-#{$background-color}-3)",
    "mix($border-color, $--color-white)": "var(--color-#{$background-color}-3)"
  },
  "element-ui/packages/theme-chalk/src/checkbox.scss": {
    "box-shadow: -1px 0 0 0 $--color-primary-light-4;": "box-shadow: -1px 0 0 0 var(--button-default-border-color-5);"
  },
  "element-ui/packages/theme-chalk/src/switch.scss": {
    "background-color: $--color-white;": "background-color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/select.scss": {
    "border-color: transparent;": "border-color: $--color-info-light;",
    "background-color: #f0f2f5;": "background-color: $--color-info-lighter;",
    "color: $--color-white;": "color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/table.scss": {
    "color: #666;": "color: $--color-text-regular;",
    "background: #FAFAFA;": "background: $--background-color-base;"
  },
  "element-ui/packages/theme-chalk/src/table-column.scss": {
    "background-color: $--color-white;": "background-color: $--popover-background-color;",
    "color: $--color-white;": "color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/date-picker/date-table.scss": {
    "color: $--color-white;": "color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/date-picker/month-table.scss": {
    "color: $--color-white;": "color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/date-picker/picker-panel.scss": {
    "background: $--color-white;": "background: $--popover-background-color;",
    "background-color: $--color-white;": "",
    "background-color: #e6f1fe;": "background-color: $--color-primary-light-9;",
    "border: 1px solid #dcdcdc;": "border: 1px solid $--border-color-base;",
    "color: #333;": "color: $--color-text-primary;",
    "color: #cccccc;": "color: $--color-text-placeholder;"
  },
  "element-ui/packages/theme-chalk/src/date-picker/date-range-picker.scss": {
    "background: $--color-white;": "background: $--popover-background-color;"
  },
  "element-ui/packages/theme-chalk/src/date-picker/time-picker.scss": {
    "background-color: $--color-white;": "background-color: $--popover-background-color;"
  },
  "element-ui/packages/theme-chalk/src/message-box.scss": {
    "background-color: $--color-white;": "background-color: $--popover-background-color;"
  },
  "element-ui/packages/theme-chalk/src/tabs.scss": {
    "border: 1px solid #d3dce6;": "border: 1px solid $--border-color-base;",
    "color: #d3dce6;": "color: $--color-text-secondary;",
    "background-color: $--color-text-placeholder;": "background-color: $--color-text-placeholder; $--color-white: var(--color-text-dark-primary);",
    "border-right-color: #fff;": "border-right-color: $--color-white;",
    "border-right: 1px solid #dfe4ed;": "border-right: 1px solid $--border-color-light;",
    "border-top-color: rgb(209, 219, 229);": "border-top-color: $--border-color-light;",
    "border-bottom-color: rgb(209, 219, 229);": "border-bottom-color: $--border-color-light;",
    "border-left-color: #fff;": "border-left-color: $--color-white;",
    "border-left: 1px solid #dfe4ed;": "border-left: 1px solid $--border-color-light;"
  },
  "element-ui/packages/theme-chalk/src/tree.scss": {
    "background: $--color-white;": "",
    "color: #fff;": "color: var(--color-text-dark-primary);",
    "mix($--color-white, $--color-primary, 92%)": "$--color-primary-light-9"
  },
  "element-ui/packages/theme-chalk/src/alert.scss": {
    "background-color: $--color-white;": "background-color: var(--color-white);",
    "color: $--color-white;": "color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/loading.scss": {
    "background-color: rgba(255, 255, 255, .9);": "background-color: var(--loading-mask-bg);"
  },
  "element-ui/packages/theme-chalk/src/progress.scss": {
    "color: $--color-white;": "color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/upload.scss": {
    "background-color: $--color-white;": "background-color: var(--color-white);",
    "background-color: #fbfdff;": "background-color: $--background-color-base;",
    "border: 1px dashed #c0ccda;": "border: 1px dashed $--border-color-base;",
    "color: #8c939d;": "color: $--color-text-regular;",
    "background-color: #fff;": "background-color: var(--color-white);",
    "border: 1px dashed #d9d9d9;": "border: 1px dashed $--border-color-base;",
    "background-color: rgba(32, 159, 255, .06);": "background-color: $--color-primary-light-9;",
    "border: 1px solid #c0ccda;": "border: 1px solid $--border-color-base;",
    "color: $--color-white;": "color: var(--color-text-dark-primary);",
    "color: #fff;": "color: var(--color-text-dark-primary);",
    "box-shadow: 0 1px 1px #ccc;": "",
    "background-color: rgba(#000, .72);": "background-color: rgba(0, 0, 0, 0.72);"
  },
  "element-ui/packages/theme-chalk/src/spinner.scss": {
    "stroke: #ececec;": "stroke: $--border-color-light;"
  },
  "element-ui/packages/theme-chalk/src/message.scss": {
    "border-color: $--border-color-lighter;": "border-color: $--color-primary-light-8;"
  },
  "element-ui/packages/theme-chalk/src/badge.scss": {
    "color: $--color-white;": "color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/carousel.scss": {
    "background-color: $--color-white;": "background-color: var(--color-text-dark-primary);",
    "color: $--color-white;": "color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/cascader.scss": {
    "background: $--cascader-tag-background;": "background: $--color-info-lighter;",
    "color: $--color-white;": "color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/color-picker.scss": {
    "border: 1px solid #dcdcdc;": "border: 1px solid $--border-color-base;",
    "color: #333;": "color: $--color-text-primary;",
    "color: #cccccc;": "color: $--color-text-placeholder;",
    "color: tint($--color-primary, $--button-hover-tint-percent);": "color: var(--color-primary-5);",
    "border: 1px solid #e6e6e6;": "border: 1px solid $--border-color-light;",
    "border: 1px solid #999;": "border: 1px solid $--color-text-placeholder;",
    "color: #999;": "color: $--color-text-placeholder;",
    "background-color: $--color-white;": "background-color: $--popover-background-color;",
    "color: $--color-white;": "color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/transfer.scss": {
    "color: $--color-white;": "color: var(--color-text-dark-primary);",
    "background: $--color-white;": ""
  },
  "element-ui/packages/theme-chalk/src/timeline-item.scss": {
    "color: $--color-white;": "color: var(--color-text-dark-primary);"
  },
  "element-ui/packages/theme-chalk/src/link.scss": {
    "mix($primaryColor, $--color-white, 80%)": "var(--color-#{$type}-5)",
    "mix($primaryColor, $--color-white, 50%)": "var(--color-#{$type}-3)"
  },
  "element-ui/packages/theme-chalk/src/button.scss": {
    "border-color: $--color-primary-light-7;": "border-color: $--color-primary-light-8;",
    "mix($--color-black, $--color-primary, $--button-active-shade-percent)": "var(--color-primary-7)",
    "@include button-variant($--button-primary-font-color, $--button-primary-background-color, $--button-primary-border-color);": "@include button-variant($--button-primary-font-color, 'primary');",
    "@include button-variant($--button-success-font-color, $--button-success-background-color, $--button-success-border-color);": "@include button-variant($--button-success-font-color, 'success');",
    "@include button-variant($--button-warning-font-color, $--button-warning-background-color, $--button-warning-border-color);": "@include button-variant($--button-warning-font-color, 'warning');",
    "@include button-variant($--button-danger-font-color, $--button-danger-background-color, $--button-danger-border-color);": "@include button-variant($--button-danger-font-color, 'danger');",
    "@include button-variant($--button-info-font-color, $--button-info-background-color, $--button-info-border-color);": "@include button-variant($--button-info-font-color, 'info');",
    "mix($--color-white, $--color-primary, $--button-hover-tint-percent)": "var(--color-primary-5)",
    "rgba($--color-white, 0.5)": "var(--color-white-5)"
  },
  "element-ui/packages/theme-chalk/src/calendar.scss": {
    "#fff": "$--color-white",
    "color: #000000;": "color: $--color-text-primary;"
  },
  "element-ui/packages/theme-chalk/src/drawer.scss": {
    "color: rgb(114, 118, 123);": "color: $--color-text-regular;"
  }
};
const DEPS_NAME = "node_modules";
const DEFAULT_ALIAS = {
  "~": DEPS_NAME
};
function transformScss(content, url, options) {
  let result = content;
  const replaces = Object.assign({}, DEFAULT_REPLACES, options == null ? void 0 : options.replaces);
  Object.keys(replaces).forEach((key) => {
    const value = replaces[key];
    if (typeof value === "string") {
      result = result.split(key).join(value);
    } else if (typeof value === "object" && typeof url === "string") {
      if (url.endsWith(key)) {
        Object.keys(value).forEach((k) => {
          const v = value[k];
          if (typeof v === "string") {
            result = result.split(k).join(v);
          }
        });
      }
    }
  });
  return result;
}
function transformAlias(url, alias) {
  const temp = Object.assign({}, DEFAULT_ALIAS, alias);
  for (const key in temp) {
    if (url.startsWith(key)) {
      return path.resolve(temp[key], url.substring(key.length));
    }
  }
  return url;
}
function checkSuffix(url) {
  if (path.basename(url).includes(".")) {
    return checkMixExists(url);
  }
  return checkMixExists(url + ".scss");
}
function checkMixExists(url) {
  if (!fs.existsSync(url)) {
    const temp = path.join(path.dirname(url), "_" + path.basename(url));
    if (fs.existsSync(temp)) {
      return temp;
    }
  }
  return url;
}
function resolveScssPath(url, prev) {
  const urlPath = transformAlias(url);
  if (path.isAbsolute(urlPath)) {
    return checkSuffix(urlPath);
  }
  return checkSuffix(path.resolve(path.dirname(transformAlias(prev)), urlPath));
}
function simplifyScssPath(url) {
  const root = `/${DEPS_NAME}/`;
  if (!url.includes(root)) {
    return url;
  }
  return "~" + url.substring(url.indexOf(root) + root.length);
}
function transformElementScss(options) {
  return (url, prev, done) => {
    const path2 = resolveScssPath(url, prev).replace(/\\/g, "/");
    if (fs.existsSync(path2)) {
      fs.readFile(path2, (error, data) => {
        if (error) {
          done(null);
        } else {
          done({
            file: simplifyScssPath(path2),
            contents: transformScss(data.toString(), path2, options)
          });
        }
      });
    } else {
      done(null);
    }
  };
}
module.exports = { transformScss, transformElementScss };
